package com.ship.control;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.ship.common.SessionInfo;
import com.ship.enume.UserType;


/**
 * 
 * @author wqf
 * @version  Jul 27, 2011 9:51:16 AM
 */
public class AbstractAdminController extends AbstractController {

	
	/**
	 * 子类必须通过此方法获取SessionInfo对象
	 * @param request
	 * @return
	 */
	public SessionInfo getSessionInfo(HttpServletRequest request){
		return authorizationCredit.getSessionInfo(request);
	}
	

	/**
	 * 控制器请求入口，内有登录判断
	 */
	public final ModelAndView handleRequestInternal(HttpServletRequest request,HttpServletResponse response)
	throws Exception {
		if(!authorizationCredit.signinValidate(request)){
			authorizationCredit.redirectSigninValidateFailView(request, response);
			return null;
		}
		else{
			return executeRequest(request,response);
		}
	}
	

	/**
	 * 请求处理方法
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	protected ModelAndView executeRequest(HttpServletRequest request,HttpServletResponse response)
		throws Exception{
		return null;
	}
		
	/**
	 * 授权信任处理对象
	 */
	private AuthorizationCredit authorizationCredit;
	private String view;
	private String selView;
	
	public void setAuthorizationCredit(AuthorizationCredit authorizationCredit) {
		this.authorizationCredit = authorizationCredit;
	}
	
	public String getView(HttpServletRequest request){
		SessionInfo sessionInfo=this.getSessionInfo(request);
		return sessionInfo.getUserType()==UserType.admin?this.view:this.selView;
	}

	public void setView(String view) {
		this.view = view;
	}
	
	public void setSelView(String selView) {
		this.selView = selView;
	}
	
}
